#include "asyncservice.h"
#include "signalservice.h"
#include <boost/bind.hpp>

SignalService::SignalService(AsyncService &service) :
    m_signalSet(service.implement())
{

}

SignalService::~SignalService()
{

}

int SignalService::addSignal(int signalNumber)
{
    ErrorCode ec;

    m_signalSet.add(signalNumber, ec);

    if(ec){
        return ec.value();
    }

    return 0;
}

void SignalService::wait(BOOST_ASIO_MOVE_ARG(Notifier) n)
{
    m_signalSet.async_wait
            (
                boost::bind
                (
                    &SignalService::onSignal,
                    this,
                    Notifier(n),
                    _1,
                    _2
                )
            );
}

void SignalService::onSignal(Notifier n, const ErrorCode &ec, int signalNumber)
{
    if(ec){
        return;
    }

    n(signalNumber);
}

